import wave
import numpy as np
from scipy import signal
from matplotlib import pyplot as plt

# 我们需要生成一个200Hz的三角波

# 生成的时长
WAVE_DURATION = 300
# 采样率
WAVE_SAMPLE_RATE = 48000
# 音频音量
WAVE_VOLUMN = 29000
# 低频
WAVE_FREQ = 200

WAVE_SEGMENTS = int(WAVE_FREQ*WAVE_DURATION)


segment = np.arange(-WAVE_VOLUMN,WAVE_VOLUMN,WAVE_SAMPLE_RATE/WAVE_FREQ)
segment = np.short(segment)

wave_file = wave.open('triwave.wav','wb')
wave_file.setnchannels(1)
wave_file.setsampwidth(2)
wave_file.setframerate(WAVE_SAMPLE_RATE)
for i in range(WAVE_SEGMENTS):
    wave_file.writeframes(segment.tobytes())
wave_file.close()